// 6.66 假设有n个结点的树T采用了双亲表示法，写出由此建立树的孩子-兄弟链表的算法。
#include <stdio.h>
#include <stdlib.h>
#include "E:\Desktop\data_struct\5TREE\1_bin_tree\creat.h"

void fun_6_66(int box[][2], int n, tree *root, int R)
{
	for (int i = 0; i < n; i++)
	{
		if (box[i][1] == R)
		{
			tree *node = (tree *)malloc(sizeof(tree));
			node->data = box[i][0];
			node->left = node->right = NULL;
			node->right = root->left;
			root->left = node;
			fun_6_66(box, n, node, i);
		}
	}
}

int main()
{
	/*******************code*******************/
	// box[i][0] -- data
	// box[i][1] -- parent
	int box[][2] = {{0, -1},
					{1, 0},
					{2, 0},
					{3, 0},
					{4, 1},
					{5, 2},
					{6, 2},
					{7, 4}};
	int n = 8;
	tree *root = (tree *)malloc(sizeof(tree));
	int i = 0;
	while (i < n && box[i][1] != -1)
	{
		i++;
	}
	root->data = box[i][0];
	root->left = root->right = NULL;
	fun_6_66(box, n, root, i);
	/******************************************/
	printf("\n\n****************************\n");
	printf("Press Enter key to continue\n");
	getchar();
	return 0;
	/******************************************/
}
